import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
	  homeImgFace: {},
	  magazineAll:{},
	  catalog:[],
	  magazineHome:{}
  },
  mutations: {
	  sethomeImgFace(state, v) {
	  	state.homeImgFace = v
	  },
	  setmagazineAll(state,v){
		  state.magazineAll = v
	  },
	  setcatalog(state,v){
		  state.catalog = v
	  },
	  setMagazineHome(state,v){
		  state.magazineHome = v
	  }
  },
  actions: {
	  queryhomeImgFace(store,v) {
	  	return new Promise((resolve, reject) => {
	  		axios.post('https://www.duzhe.com/home/reader/magazine/bannerList')
	  			.then(resp => {
	  				// console.log(resp)
					store.commit('sethomeImgFace',resp.data.data[0])
	  				resolve()
	  			})
	  			.catch(err => {
	  				reject(err)
	  			})
	  
	  	})
	  },
	  queryshuju(store,v) {
	  	return new Promise((resolve, reject) => {
	  		axios.post('https://www.duzhe.com/home/reader/magazine/list',v)
	  			.then(resp => {
	  				// console.log(resp.data.data)
	  			    store.commit('setmagazineAll',resp.data.data)
	  				resolve(resp.data.data)
	  			})
	  			.catch(err => {
	  				reject(err)
	  			})
	  	})
	  },
	  queryCatalog(store,v) {
	  	return new Promise((resolve, reject) => {
	  		axios.post('https://www.duzhe.com/home/reader/magazine/catalog',v)
	  			.then(resp => {
	  				// console.log(resp.data.data)
	  			    store.commit('setcatalog',resp.data.data)
	  				resolve(resp.data.data)
	  			})
	  			.catch(err => {
	  				reject(err)
	  			})
	  	})
	  },
	  queryMagazineHome(store,v) {
	  	return new Promise((resolve, reject) => {
	  		axios.post('https://www.duzhe.com/home/reader/magazine/magazineHome',v)
	  			.then(resp => {
	  				// console.log(resp.data.data)
	  			    store.commit('setMagazineHome',resp.data.data)
	  				resolve(resp.data.data)
	  			})
	  			.catch(err => {
	  				reject(err)
	  			})
	  	})
	  }
  },
  modules: {
  }
})
